home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.cyberramp.net!news
- From: sinan@cyberramp.net (John Noland)
- Newsgroups: comp.lang.c
- Subject: Re: Packing and Unpacking Numeric Data
- Date: 22 Feb 1996 01:17:32 GMT
- Organization: Prose Software
- Message-ID: <4ggg7c$kpg@newshost.cyberramp.net>
- References: <31250EE4.3642@cybercomm.net>
- NNTP-Posting-Host: ramp1-23.cyberramp.net
- X-Newsreader: WinVN 0.99.5
-
- In article <31250EE4.3642@cybercomm.net>, fschitto@cybercomm.net says...
- >
- >This is our situation.
- >
- >We need to transfer data from Unix/Oracle/C to MVS cobol and from MVS/Cobol
- >to Unix/Oracle/C. We are being asked to transfer the data to MVS from UNIX
- >in a format that MVS/COBOL can understand. The problem is with MVS Cobol
- >COMP-3 fields and Zoned decimal. My question is, Is their a utility in C, on
- >the UNIX side, which will convert numeric data to Packed Decimal or Zoned
- >Decimal and also convert back from Packed Decimal or Zoned Decimal to Numeric
- >data.
- >
- >Please note that may programming skills with C are not that great.
- >
- >Any Help in this matter would be greatly appreciated.
-
- This probably isn't the right place for you to post this. But, too
- late now.
-
- Here are a couple of routines that I did for a COBOL to C conversion.
- Note that these routines are for DOS/Intel. Your int's will be 32 bit+
- instead of 16 bit, and the byte storage on your computer may differ.
- The principal should be the same though. I included the comp-5 routine
- just to illustrate how to handle odd byte sizes. The comp5_long()
- routine takes a pointer to 3-byte character array.
- In my opinion, the conversion is easier from the COBOL side. I would
- suggest that you determine the COBOL data types that correspond to
- the standard C types. For example, PIC S9(9) comp-5 would correspond
- to a 32 bit integer (long for me, probably int for you). Once you've
- figured out the corresponding data types, a simple move from a comp-3
- field to a comp-5 will convert it and vice-versa.
-
-
- /*********************** comp3_int **************************************
- Converts a COBOL 2 byte comp-3 (3 digit packed decimal) to a 2 byte integer.
- ************************************************************************/
-
- int comp3_int(int convertee){
-
- int packdec1, packdec2, packdec3;
-
- packdec1 = convertee; /* Decimal 100's place */
- packdec2 = convertee; /* Decimal 10's place */
- packdec3 = convertee; /* Decimal 1's place */
- packdec1 &= 0xF0;
- packdec1 >>= 4;
- packdec1 *= 100;
- packdec2 &= 0xf;
- packdec2 *= 10;
- packdec3 >>= 12;
- return(packdec1 + packdec2 + packdec3);
- }
-
-
- /************************ comp5_long ***********************************
- Converts a COBOL 3 byte comp-5 to a 4 byte long integer.
- ***********************************************************************/
-
- long comp5_long(char *s){
-
- union {
- char c_num[4];
- long l_num;
- } r_num_cnv;
-
- r_num_cnv.c_num[0] = s[0];
- r_num_cnv.c_num[1] = s[1];
- r_num_cnv.c_num[2] = s[2];
- r_num_cnv.c_num[3] = 0;
- return(r_num_cnv.l_num);
- }
-
-